HTMLify
Left Rotate an array by one place.cpp
Views: 1 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class Solution{ public: void leftRotate(int arr[], int k, int n) { // Your code goes here k = k % n; int temp[k]; for(int i =0; i<k; i++){ temp[i] = arr[i]; } // Shifting for(int i = k; i<n; i++){ arr[i-k] = arr[i]; } // reverse back temp for(int i = n - k; i<n; i++){ arr[i] = temp[i - (n - k)]; } } }; |